<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
</head>


<body>
    <script src="../js/mui.min.js"></script>
    <script src="../js/vue.min.js"></script>
    <script src="../js/url.js"></script>
    <script src="../js/ajax.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript">

        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }

        var code = GetQueryString("code");
        var state = GetQueryString("state");
        var str = state.split("@");


        console.log(code);
        console.log(state);
        console.log(str);


        var id = str[0];  //  商品  文章  视频 id
        var shopId = str[1];
        var userId = str[2]; //分享者id
        var flag = str[3];   // 0商品  1 文章  2 视频  3储值金

        sessionStorage.zhtxFlag = flag
        sessionStorage.zhtxId = id

        sessionStorage.shopId = shopId
        sessionStorage.userId = userId

        alert(flag)
        alert(id)
        alert(shopId)
        alert(userId)

        var app = new Vue({
            el: '#app',
            data: {

            },
            methods: {
                getData: function () {
                    var _this = this;
                    console.log(code);
                    alert(code)
                    var sendStr = userId + '@' + shopId + '@' + id + '@' + flag
                    ajax({
                        url: newUrl + "user/toShare",
                        type: 'post',
                        data: {
                            code: code,
                            state: sendStr,
                        },
                        dataType: 'json',
                        timeout: 10000,
                        contentType: "application/json",
                        success: function (data) {
                            alert(data)
                            var data = JSON.parse(data)
                            if (data.flag) {

                                var results = data.data;
                                if (results.flag == "error") {
                                    alert(results.msg);
                                    return;
                                } else {

                                    // alert(results)
                                    // return
                                    sessionStorage.nowUserId = 1
                                    sessionStorage.openId = results.openId;

                                    if (flag == 0) {//商品
                                        window.location.replace("rechargeProduct.html")
                                    }

                                    if (flag == 1 || flag == 2) {//文章 或 视频
                                        window.location.replace("contentDetail.html")
                                    }

                                    if (flag == 3) {  //  储值金首页
                                        window.location.replace("rechargeIndex.html")
                                    }

                                }
                            }
                        },
                    })
                },
            },
            created: function () {
                this.getData();
            }
        })
    </script>
</body>

</html>